package com.ghsc.ghxc.jsb.ui.message.view.gif.adapter

import android.view.View
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.cn.appcore.ext.getCompatColor
import com.cn.appcore.utils.GlideUtil
import com.flyco.roundview.RoundLinearLayout
import com.ghsc.ghxc.jsb.R
import com.ghsc.ghxc.jsb.ui.live.bean.GifDataBean
import com.ghsc.ghxc.jsb.ui.live.view.gif.adapter.GifListAdapter
import com.ghsc.ghxc.jsb.utils.StringUtil

/**
 * 项目：GuoHuaMall
 * 包名：com.ghsc.ghxc.ui.live.view.gif.adapter
 * 类名：GifViewpagerListAdapter
 * 创建时间：2023/9/14 22:57
 * 创建人 @author： xiaolin
 * 描述 ：Todo...
 */
class GifViewpagerListAdapter   : BaseQuickAdapter<MutableList<GifDataBean>, BaseViewHolder>(R.layout.pw_gif_gird_view){
    var myItemClick: MyItemClick? = null
    fun GifViewpagerListAdapter(myItemClick: MyItemClick?) {
        this.myItemClick = myItemClick
    }
    override fun convert(helper: BaseViewHolder, item: MutableList<GifDataBean>) {
        var rvList=helper.getView<RecyclerView>(R.id.rv_list)
        rvList.layoutManager = GridLayoutManager(this.context, 4)
        var mAdapter= GifListAdapter()
        rvList.adapter =mAdapter
        mAdapter.replaceData(item)
        mAdapter.setOnItemClickListener { adapter, view, position ->
            myItemClick!!.onItemClick(view,position,helper.position)
        }
    }

    interface MyItemClick {
        fun onItemClick(view: View?, postion: Int, supPosition:Int)
    }


}



class GifListAdapter  : BaseQuickAdapter<GifDataBean, BaseViewHolder>(R.layout.item_gridview_gif){
    override fun convert(helper: BaseViewHolder, item: GifDataBean) {
        var width:Float= this.context.resources.displayMetrics.widthPixels / this.context.resources.displayMetrics.density
        var llItem= helper.getView<RoundLinearLayout>(R.id.ll_item)
        val para1 = llItem.layoutParams
        para1.width = StringUtil.dp2px((width/4)).toInt()  - StringUtil.dp2px(8f).toInt()
        llItem.layoutParams = para1
        helper.setText(R.id.name,item.name)
            .setText(R.id.price, item.price)
        GlideUtil.ImageLoad(this.context,item.images,helper.getView(R.id.images))

        if (item.isCheck){
            llItem.delegate.strokeColor= this.context.getCompatColor(R.color.gif_item_bk)
            llItem.delegate.backgroundColor= this.context.getCompatColor(R.color.gif_item_bg)
        }else  {
            llItem.delegate.strokeColor=0
            llItem.delegate.backgroundColor=0
        }
    }
}